<?php
include 'SqlConnect.php';

// 创建数据库连接
$conn = new mysqli($servername, $username, $password, $dbname);

// 检查连接
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
}

// 处理表单提交
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // 获取表单数据
    $ProductNum = $_POST['ProductNum'];
    $ProductModel = $_POST['ProductModel'];
    $ProductName = $_POST['ProductName'];
    $CustomerName = $_POST['CustomerName'];
    $OrderDate = $_POST['OrderDate'];
    $Sales = $_POST['Sales'];
    $Ps = $_POST['Ps'];
    $PlanDays = $_POST['PlanDays'];
    $Complete = $_POST['Complete'];
    
    // 增
    
    $sql = "INSERT INTO manager (ProductNum, ProductModel, ProductName,CustomerName,OrderDate,Sales,Ps,PlanDays,Complete) VALUES ($ProductNum, '$ProductModel', '$ProductName','$CustomerName','$OrderDate','$Sales','$Ps',$PlanDays,'$Complete')";
    if ($conn->query($sql) === TRUE) {
        echo "<script>alert('新记录插入成功。最后插入的产品便好: $ProductNum')</script>";
        header("Refresh:1; url=manager.html");
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }
    // 删
    // else if ($action == 'delete') {
    //     $sql = "DELETE FROM users WHERE id = $id";
    //     if ($conn->query($sql) === TRUE) {
    //         echo "<div style='color:green;'>记录删除成功</div>";
    //     } else {
    //         echo "<div style='color:red;'>Error: " . $sql . "<br>" . $conn->error . "</div>";
    //     }
    // }
    // 改
    // else if ($action == 'update') {
    //     $sql = "UPDATE users SET name='$name', age='$age', email='$email' WHERE id=$id";
    //     if ($conn->query($sql) === TRUE) {
    //         echo "<div style='color:green;'>记录更新成功</div>";
    //     } else {
    //         echo "<div style='color:red;'>Error: " . $sql . "<br>" . $conn->error . "</div>";
    //     }
    // }
}

// 查询数据
// $sql = "SELECT id, name, age, email FROM users";
// $result = $conn->query($sql);

// 关闭数据库连接
$conn->close();
?>



